# -*- coding: UTF-8 -*-

from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired, FileAllowed
from wtforms import StringField, PasswordField, SubmitField, FileField
from wtforms.validators import DataRequired, Length


class LoginForm(FlaskForm):
    account = StringField(label='账号',
                          validators=[DataRequired()],
                          render_kw={'class': 'form-control'})
    password = PasswordField(label='密码',
                             validators=[DataRequired(),
                                         Length(2, 8, '密码长度必须在2-8之间')],
                             render_kw={'class': 'form-control'})
    submit = SubmitField('登录', render_kw={'class': 'btn btn-primary'})


class SignForm(FlaskForm):
    name = StringField(label='用户名称',
                       validators=[DataRequired()],
                       render_kw={'class': 'form-control'})
    account = StringField(label='账号',
                          validators=[DataRequired(),
                                      Length(2, 32, '密码长度必须在2-32之间')],
                          render_kw={'class': 'form-control'})
    password = PasswordField(label='密码',
                             validators=[DataRequired(),
                                         Length(2, 8, '密码长度必须在2-8之间')],
                             render_kw={'class': 'form-control'})
    password2 = PasswordField(
        label="重复密码",
        validators=[DataRequired(),
                    Length(2, 8, '密码长度必须在2-8之间')],
        render_kw={'class': 'form-control'})

    submit = SubmitField('注册', render_kw={'class': 'btn btn-primary'})


class UserForm(FlaskForm):
    name = StringField(label='用户名称',
                       validators=[DataRequired()],
                       render_kw={'class': 'form-control'})
    account = StringField(label='账号',
                          validators=[DataRequired(),
                                      Length(2, 32, '密码长度必须在2-32之间')],
                          render_kw={'class': 'form-control'})
    password = PasswordField(label='密码',
                             validators=[DataRequired(),
                                         Length(2, 8, '密码长度必须在2-8之间')],
                             render_kw={'class': 'form-control'})
    password2 = PasswordField(
        label="重复密码",
        validators=[DataRequired(),
                    Length(2, 8, '密码长度必须在2-8之间')],
        render_kw={'class': 'form-control'})

    submit = SubmitField('保存', render_kw={'class': 'btn btn-primary'})


class UserUpdateForm(FlaskForm):
    name = StringField(label='用户名称',
                       validators=[DataRequired()],
                       render_kw={'class': 'form-control'})
    account = StringField(label='账号',
                          validators=[DataRequired(),
                                      Length(2, 32, '密码长度必须在2-32之间')],
                          render_kw={'class': 'form-control', 'readonly': True})
    password = PasswordField(label='密码',
                             validators=[DataRequired(),
                                         Length(2, 8, '密码长度必须在2-8之间')],
                             render_kw={'class': 'form-control'})
    password2 = PasswordField(
        label="重复密码",
        validators=[DataRequired(),
                    Length(2, 8, '密码长度必须在2-8之间')],
        render_kw={'class': 'form-control'})

    submit = SubmitField('提交', render_kw={'class': 'btn btn-primary'})


class CarForm(FlaskForm):
    code = StringField(label='编号', validators=[DataRequired()], render_kw={'class': 'form-control'})
    name = StringField(label='名称', validators=[DataRequired()], render_kw={'class': 'form-control'})
    color = StringField(label='颜色', validators=[DataRequired()], render_kw={'class': 'form-control'})

    price = StringField(label='价格', validators=[DataRequired()], render_kw={'class': 'form-control'})
    performance = StringField(label='性能', validators=[DataRequired()], render_kw={'class': 'form-control'})
    model = StringField(label='型号', validators=[DataRequired()], render_kw={'class': 'form-control'})
    size = StringField(label='大小', validators=[DataRequired()], render_kw={'class': 'form-control'})
    icon_file = FileField(
        label="图片",
        validators=[FileRequired(), FileAllowed(['jpg', 'png', 'jpeg'], '只接收.jpg,.png和.jpeg格式的图片')]
    )
    # MultipleFileField

    submit = SubmitField('提交', render_kw={'class': 'btn btn-primary'})
